using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Runtime.CompilerServices;
using Unity.Burst;
using Unity.Mathematics;
using UnityEngine;

public class MonsterBehaviour : BasePoolElement
{
    public MonsterSetting settings;
    public BehaviourPropertys propertys;

    Vector3 dir;
    float time;
    float lifeTime;
    public void Awake()
    {
        propertys = new BehaviourPropertys();
    }
    public override void PoolInit()
    {
        transform.position = Vector3.zero;
        transform.localScale = Vector3.one;
        time = 0;
        lifeTime = UnityEngine.Random.Range(3, 6);
        dir = UnityEngine.Random.insideUnitSphere;
        dir.y = 0;
    }

    public void InitSetting(int id)
    {
        settings = TableDataMgr.Instance.MonsterSettingTB[id.ToString()];
        InitProperties();
    }


    void InitProperties()
    {
        propertys.Clear();
        propertys.InitFrom(settings);
        

        propertys.Add(PropertyEnum.Hp, 100);
        propertys.Mul(PropertyEnum.Hp, .5f);
        Debug.Log($"init properties:{propertys.Value(PropertyEnum.Hp)}");
    }

    private void FixedUpdate()
    {
        time += Time.fixedDeltaTime;
        if (time > lifeTime)
        {
            ObjectPoolManager.Instance.EnPool(this);
        }
        transform.position += dir * Time.fixedDeltaTime;
        transform.localScale = Vector3.one * (0.75f + Mathf.PingPong(time, 1));
    }
}

